package com.zhou.springboot.dao;

import com.zhou.springboot.entity.Person;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;


/**
 * author : zhoujb
 * created : 2020/6/28.
 * QQ : 1377072049
 */
public interface PersonDao extends JpaRepository<Person,Long> {
    @Transactional//事务的注解
    @Modifying//增删改必须有这个注解
    @Query("update Person person set " +
            "person.name = CASE WHEN :#{#person.name} IS NULL THEN person.name ELSE :#{#person.name} END ," +
            "person.age = CASE WHEN :#{#person.age} IS NULL THEN person.age ELSE :#{#person.age} END ," +
            "person.job = CASE WHEN :#{#person.job} IS NULL THEN person.job ELSE :#{#person.job} END " +
            "where person.id = :#{#person.id}")
    int updatePerson(@Param("person") Person person);

}
